import wepy from 'wepy';
import tools from './tools';

const gData = {

  appId: 'wxd7c977843ebe7a64',  // 酷酷
  hotelId: 'B335C79F2B7748A49DCF962BDBC8D220',

  // appId: 'wxb46de75b993fa52c',  // 摩登克斯
  // hotelId: '307dcee9913249d592b91b8394c91d18',

  // appId: 'wxcc6022e41ffd305f',  // 城市客栈锦绣中华店
  // hotelId: '894939622876409ebd4c25517ead735a',

  // appId: 'wxebcfc62b5fcec5e3',  // 城市客栈创意园店
  // hotelId: 'fdd2ff99adf541e19198663b8e63ff3b',

  // appId: 'wx9b063a158b908b0b',  // 山西水密芭莎温泉酒店
  // hotelId: '81ce7aab0b004141bf58142ccb9ad484',

  // appId: 'wxaee07f8d4fbd041a',  // 山西田舍酒店
  // hotelId: 'ZRB13RAOZQTTGRON3YVH53RXZGFO3IJ7E5U02SNU',

  //正式
  // cm_host: 'https://cm.zigbeei.com/CenterMaster/',
  // wx_host: 'https://wx.zigbeei.com/hotel_wx/rest/'

  //开发
  cm_host: 'https://dev.zigbeei.com/CenterMaster/',
  wx_host: 'https://dev.zigbeei.com/hotel_wx/rest/'
}

export default {

  errorCenter : (self, type, errMsg, logType, clientMethod, costTime, serviceName, serviceId, contentIn, contentOut, contentException, isNote, isLoading) => {

    let exceptionName = ''
    if (type == 'error') {
      exceptionName = contentOut.returnMessage
      errMsg = errMsg + '错误（' + contentOut.returnMessage + '）,请重试~'
    } else if (type == 'fail') {
      exceptionName = JSON.stringify(contentOut)
      if (exceptionName.errMsg == 'request:fail timeout') {
        errMsg = errMsg + '失败,请求超时,请重试~'
      } else {
        errMsg = errMsg + '失败（' + JSON.stringify(contentOut) + '）,请重试'
      }
    }
    let d = new Date()
    let month = (d.getMonth() + 1) > 9
      ? (d.getMonth() + 1)
      : '0' + (d.getMonth() + 1)
    let day = d.getDate() > 9
      ? d.getDate()
      : '0' + d.getDate()
    let hh = d.getHours() > 9
      ? d.getHours()
      : '0' + d.getHours()
    let mm = d.getMinutes() > 9
      ? d.getMinutes()
      : '0' + d.getMinutes()
    let ss = d.getSeconds() > 9
      ? d.getSeconds()
      : '0' + d.getSeconds()
    //JSON.stringify(contentIn, null, 2),
    let parms = {
      logType: logType,
      clientMethod: clientMethod,
      costTime: costTime,
      serviceName: serviceName,
      serviceId: serviceId,
      contentIn: JSON.stringify(contentIn, null, 2),
      contentOut: JSON.stringify(contentOut, null, 2),
      contentException: JSON.stringify(contentException, null, 2),
      clientType: 202,
      clientId: gData.hotelId,
      exceptionName: '',
      clientTime: d.getFullYear() + month + day + hh + mm + ss
    }
    wepy.request({
      url: 'https://log.zigbeei.com/SystemLog/web/logs/insertLog',
      data: tools.jsonToUrl(parms),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {},
      fail: function(error) {}
    })
    if (isNote == -1) {} else {
      if (logType == 1001 || logType == 1003) {
        wepy.showModal({
          title: '提示信息',
          content: errMsg,
          showCancel: false,
          confirmText: '关闭',
          confirmColor: '#999',
          success: function(res) {
            if (res.confirm) {
              //wepy.switchTab({url: '/pages/room/select_room'})
              /**
              wepy.request({
                url: 'https://log.bookingyun.com/SystemLog/web/logs/insertLog',
                data: tools.jsonToUrl(parms),
                method: 'POST',
                header: {
                  'content-type': 'application/x-www-form-urlencoded'
                },
                success: function(res) {
                  if (res.data.code == '1') {
                    wx.showToast({title: '提交成功', icon: 'success', duration: 2000})
                  }
                  console.log(res);
                },
                fail: function(error) {}
              })
              **/
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    }
  },
  request(self, data, suss, fail) {
    let start = new Date().getTime()
    let serviceId = ''
    if (data.url.indexOf('hotel_wx') > -1) {
      serviceId = 3
    } else {
      serviceId = 1
    }
    if (data.method == undefined) {
      data.method = 'GET'
    }

    if (data.isNote != -1 && data.isLoading) {
      //兼容处理
      if (wepy.showLoading) {
        wepy.showLoading({title: '努力加载中', mask: true})
      } else {
        wepy.showToast({title: '正在加载', icon: 'loading', duration: 1500, mask: true})
      }

    }

    gData.url = data.url

    wepy.showNavigationBarLoading()
    wepy.request({
      url: data.url,
      data: data.data,
      header: data.header,
      method: data.method,
      success: function(res) {
        wepy.hideNavigationBarLoading()
        if (data.isNote != -1 && data.isLoading) {
          if (wepy.hideLoading) {
            wepy.hideLoading()
          }
        }
        let end = new Date().getTime()
        let d = res.data
        if (d.returnCode === '1' || d.returnCode === 1) {
          suss(d)
          self.errorCenter(self, 'error', data.text, 1002, data.method, end - start, data.sName, serviceId, data.data, d, gData, data.isNote, data.isLoading)
        } else if (d.returnCode == 'X108001' || d.returnCode == 'X108002') {
          d.returnMessage = '此房间已被抢先支付，请重新选择房间号'
          fail('此房间已被抢先支付，请重新选择房间号')
          self.errorCenter(self, 'error', data.text, 1003, data.method, end - start, data.sName, serviceId, data.data, d, gData, data.isNote, data.isLoading)
        } else if (d.returnCode == '10008') {
          fail(d)
          self.errorCenter(self, 'error', data.text, 1003, data.method, end - start, data.sName, serviceId, data.data, d, gData, -1, data.isLoading)
        } else if (d.returnCode == '20002') {
          fail(d)
          self.errorCenter(self, 'error', data.text, 1003, data.method, end - start, data.sName, serviceId, data.data, d, gData, -1, data.isLoading)
        } else {
          fail(d.returnMessage)
          self.errorCenter(self, 'error', data.text, 1003, data.method, end - start, data.sName, serviceId, data.data, d, gData, data.isNote, data.isLoading)
        }
      },
      fail: function(error) {
        wepy.hideNavigationBarLoading()
        if (wepy.hideLoading) {
          wepy.hideLoading()
        }
        let end = new Date().getTime()
        fail(JSON.stringify(error))
        self.errorCenter(self, 'fail', data.text, 1001, data.method, end - start, data.sName, serviceId, data.data, error, gData, data.isNote, data.isLoading)
      }
    })
  },

  //解析数据
  getSNSUserInfoByEncryptedData(parms, suss, fail) {
    let data = {
      url: gData.wx_host + 'wxRest/getSNSUserInfoByEncryptedData',
      sName: 'wxRest/getSNSUserInfoByEncryptedData',
      text: '解析数据',
      method: 'GET',
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取手机号码
  getPhoneNumberByEncryptedData(parms, suss, fail) {
    let data = {
      url: gData.wx_host + 'wxRest/getPhoneNumberByEncryptedData',
      sName: 'wxRest/getPhoneNumberByEncryptedData',
      text: '获取手机号码',
      method: 'GET',
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取用户信息
  getUserByOpenId(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getUserByOpenId',
      sName: 'user/getUserByOpenId',
      text: '获取用户信息',
      method: 'GET',
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //保存小程序表单Id
  saveLittleAppFormId(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/saveLittleAppFormId',
      sName: 'user/saveLittleAppFormId',
      text: '保存小程序表单Id',
      method: 'GET',
      isNote: -1, //-1代表不给用户报错
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },

  //发送验证码
  sendVerifyCode(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/sendVerifyCode',
      sName: 'user/sendVerifyCode',
      text: '发送验证码',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //更新/设置用户手机号码
  updateUserPnone(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/updateUserPnone',
      sName: 'user/updateUserPnone',
      text: '更新/设置用户手机号码',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //微信小程序扫码获取用户信息
  getUserBySceneStr(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getUserBySceneStr',
      sName: 'user/getUserBySceneStr',
      text: '扫码获取用户信息',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //酒店微信小程序绑定用户
  hotelWechatLittleAppBindUser(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/hotelWechatLittleAppBindUser',
      sName: 'user/hotelWechatLittleAppBindUser',
      text: '与酒店关联',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取用于分享的协议单位
  getShareAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getShareAgreeUnit',
      sName: 'user/getShareAgreeUnit',
      text: '请求协议单位详情',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //记录协议单位分享
  recordShareAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/recordShareAgreeUnit',
      sName: 'user/recordShareAgreeUnit',
      text: '记录分享',
      method: 'GET',
      data: parms,
      isLoading: false,
      isNote: -1, //-1代表不给用户报错
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //领取分享的协议单位
  receiveShareAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/receiveShareAgreeUnit',
      sName: 'user/receiveShareAgreeUnit',
      text: '领取协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取协议单位分享记录
  getShareAgreeUnitRecord(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getShareAgreeUnitRecord',
      sName: 'user/getShareAgreeUnitRecord',
      text: '获取协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },


  //请求房型列表
  getRoomTypeList(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'room/getRoomTypeList',
      sName: 'room/getRoomTypeList',
      text: '请求房型列表',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //请求房间列表
  getRoomListByRoomType(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'room/getRoomListByRoomType',
      sName: 'room/getRoomListByRoomType',
      text: '请求房间列表',
      method: 'GET',
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },

  //获取用户住客列表
  getUserContacters(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getUserContacters',
      sName: 'user/getUserContacters',
      text: '获取住客列表',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //添加住客
  addContacter(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/addContacter',
      sName: 'user/addContacter',
      text: '添加住客',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //更新住客
  updateContacter(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/updateContacter',
      sName: 'user/updateContacter',
      text: '更新住客',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //删除住客
  deleteContacter(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/deleteContacter',
      sName: 'user/deleteContacter',
      text: '删除住客',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },

  /**
   * 酒店模块
   */
  //获取酒店详情
  getHotelInfoByID(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'hotel/getHotelInfoByID',
      sName: 'hotel/getHotelInfoByID',
      text: '获取酒店详情',
      method: 'GET',
      data: parms,
      isLoading: false,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取酒店周边列表  编辑
  getHotelAroundList(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'hotel/getHotelAroundList',
      sName: 'hotel/getHotelAroundList',
      text: '获取酒店图片',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  /**
   * 订单模块
   */
  //提交订单
  submitOrder(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/submitOrder',
      sName: 'order/submitOrder',
      text: '订单提交',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //续住订单
  continuedTolive(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/continuedTolive',
      sName: 'order/continuedTolive',
      text: '续住',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //取消订单
  cancelOrder(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/cancelOrder',
      sName: 'order/cancelOrder',
      text: '取消订单',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //意图退房
  intentCheckOut(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/intentCheckOut',
      sName: 'order/intentCheckOut',
      text: '预约退房',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //请求订单列表
  getOrderList(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/getOrderList',
      sName: 'order/getOrderList',
      text: '请求订单列表',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //请求订单列表(手机号码)
  getOrderListByPhone(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/getOrderListByPhone',
      sName: 'order/getOrderListByPhone',
      text: '请求订单列表',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //请求订单列表(关键字)
  queryOrderList(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/queryOrderList',
      sName: 'order/queryOrderList',
      text: '请求订单列表',
      method: 'GET',
      data: parms,
      isLoading: false,
      isNote: -1, //-1代表不给用户报错
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },

  //请求订单详情
  getOrderDetail(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/getOrderDetail',
      sName: 'order/getOrderDetail',
      text: '请求订单详情',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },

  //小程序客房扫码查询订单
  littleAppRoomScan(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/littleAppRoomScan',
      sName: 'order/littleAppRoomScan',
      text: '查询订单',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },


  //添加同住人
  addLiveInUser(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/addLiveInUser',
      sName: 'order/addLiveInUser',
      text: '添加同住人',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //删除同住人
  deleteAppendLiveInUser(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/deleteAppendLiveInUser',
      sName: 'order/deleteAppendLiveInUser',
      text: '删除同住人',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //订单选择发票
  selectInvoiceHead(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/selectInvoiceHead',
      sName: 'order/selectInvoiceHead',
      text: '选择发票',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //中间人领取订单
  middleManReciveOrder(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'order/middleManReciveOrder',
      sName: 'order/middleManReciveOrder',
      text: '领取订单',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },


  //获取微信js支付参数
  getWxJsPayParams(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'WeChat/getWxJsPayParams',
      sName: 'WeChat/getWxJsPayParams',
      text: '获取支付参数',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //一键开门
  openDoor(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'device/openDoor',
      sName: 'device/openDoor',
      text: '一键开门',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  /**
   * 发票模块
   * @type {[type]}
   */
  //添加发票抬头
  addInvoiceHead(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/addInvoiceHead',
      sName: 'user/addInvoiceHead',
      text: '添加发票抬头',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //修改发票抬头
  updateInvoiceHead(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/updateInvoiceHead',
      sName: 'user/updateInvoiceHead',
      text: '修改发票抬头',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //删除发票抬头
  deleteInvoiceHead(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/deleteInvoiceHead',
      sName: 'user/deleteInvoiceHead',
      text: '删除发票抬头',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取发票抬头列表
  getUserInvoiceHeads(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getUserInvoiceHeads',
      sName: 'user/getUserInvoiceHeads',
      text: '获取发票抬头列表',
      method: 'GET',
      data: parms,
      isLoading: parms.isLoading,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  /**
   * 协议单位模块
   * @type {[type]}
   */
  //协议单位模糊查询
  getAgreeUnitListByName(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'agreeUnit/getAgreeUnitListByName',
      sName: 'agreeUnit/getAgreeUnitListByName',
      text: '查询协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //获取协议单位列表
  getAgreeUnitListByUserId(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/getAgreeUnitListByUserId',
      sName: 'user/getAgreeUnitListByUserId',
      text: '获取协议单位列表',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //添加协议单位
  addUserAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/addUserAgreeUnit',
      sName: 'user/addUserAgreeUnit',
      text: '添加协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //删除协议单位
  deleteUserAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/deleteUserAgreeUnit',
      sName: 'user/deleteUserAgreeUnit',
      text: '删除协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  //绑定协议单位
  setUserDefaultAgreeUnit(parms, suss, fail) {
    let data = {
      url: gData.cm_host + 'user/setUserDefaultAgreeUnit',
      sName: 'user/setUserDefaultAgreeUnit',
      text: '绑定协议单位',
      method: 'GET',
      data: parms,
      isLoading: true,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }
    };
    this.request(this, data, suss, fail)
  },
  /**
   * 微信官方API
   */
  //获取设备信息
  getSystemInfo() {
    let self = this
    let start = new Date().getTime()
    try {
      var res = wepy.getSystemInfoSync()
      return res
    } catch (e) {
      let end = new Date().getTime()
      e.returnMessage = JSON.stringify(e)
      self.errorCenter(self, 'error', '获取视图信息', 2001, 'wx', end - start, 'wx.getSystemInfoSync()', '', e, e, gData)
      return null
      // Do something when catch error
    }
  },

  test(parms, suss, fail) {
    wepy.request({
      url: 'http://pis.baiwang.com/scan/title/submit',
      data: tools.jsonToUrl({
        merchantID: 'd655cdee-1bbe-4c3f-bf39-5b196df7f2ab',
        scanType: 'other',
        unitName: '深圳市范德萨实业有限公司',
        phoneNo: '17097225550',
        titleType: '0',
        email: '123123@qq.com',
        unitTaxNo: '91440300MA5DCL9241',
        bankName: '',
        bankNo: '',
        unitAddress: '',
        unitPhone: '',
        uuid: 'okKnBwlvuaQF-nxAFJVNpw3KEnvU'
      }),
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res) {
        console.log("res");
        console.log(res);
      },
      fail: function(error) {
        console.log("error");
        console.log(error);
        console.log(error);
      }
    })

  },

  /**
   * 自定义API
   */
  //返回全局数据
  getApiGData : (index) => {
    return gData
  }
};
